/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jule.clases.treeFiles;

import java.io.File;

import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;

public class FileSystemModel implements TreeModel {

       public DirectoryNode root = null;

       public FileSystemModel(String rootDirPath) {
               File rootFile = new File(rootDirPath);
               if (!rootFile.exists()) {
                       throw new IllegalArgumentException("Root path " + rootDirPath
                                       + " not exist.");
               }
               root = new DirectoryNode(rootFile);
       }

       public void addTreeModelListener(TreeModelListener arg0) {
               // do nothing
       }

       public Object getChild(Object arg0, int arg1) {
               if (arg0 instanceof FileNode) {
                       return null;
               } else {
                       DirectoryNode dirNode = (DirectoryNode) arg0;
                       if (dirNode.toString().contains("svn"))
                       {
                           
                       }
                       return dirNode.getChildAt(arg1);
               }
       }

       public int getChildCount(Object arg0) {
               if (arg0 instanceof FileNode) {
                       return 0;
               } else {
                       DirectoryNode dirNode = (DirectoryNode) arg0;
                       return dirNode.getChildCount();
               }
       }

       public int getIndexOfChild(Object arg0, Object arg1) {
               if (TreeNode.class.isAssignableFrom(arg0.getClass())) {
                       TreeNode node = (TreeNode) arg0;
                       return node.getIndex((TreeNode) arg1);
               } else {
                       return -1;
               }
       }

       public Object getRoot() {
               return root;
       }

       public boolean isLeaf(Object arg0) {
               if (TreeNode.class.isAssignableFrom(arg0.getClass())) {
                       TreeNode node = (TreeNode) arg0;
                       return node.isLeaf();
               } else {
                       return false;
               }
       }

       public void removeTreeModelListener(TreeModelListener arg0) {
               // do nothing
       }

       public void valueForPathChanged(TreePath arg0, Object arg1) {
               // do nothing
       }
}

  
 


